<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php /* @var $block \Magento\Downloadable\Block\Adminhtml\Catalog\Product\Composite\Fieldset\Downloadable */ ?>
<?php $_linksPurchasedSeparately = $block->getLinksPurchasedSeparately(); ?>
<?php $_skipSaleableCheck = $this->helper('Magento\Catalog\Helper\Product')->getSkipSaleableCheck(); ?>
<?php if (($block->getProduct()->isSaleable() || $_skipSaleableCheck) && $block->hasLinks()):?>

<fieldset id="catalog_product_composite_configure_fields_downloadable"
          class="fieldset admin__fieldset downloadable information<?php echo $block->getIsLastFieldset() ? ' last-fieldset' : '' ?>">
    <legend class="legend admin__legend"><span><?php /* @escapeNotVerified */ echo __('Downloadable Information') ?></span></legend><br />
    <?php $_links = $block->getLinks(); ?>
    <?php $_isRequired = $block->getLinkSelectionRequired(); ?>
    <div class="field admin__field link<?php if ($_isRequired) echo ' required _required' ?>">
        <label class="label admin__field-label"><span><?php /* @escapeNotVerified */ echo $block->getLinksTitle() ?></span></label>
        <div class="control admin__field-control" id="downloadable-links-list">
            <?php foreach ($_links as $_link): ?>
                <div class="nested admin__field-option">
                <?php if ($_linksPurchasedSeparately): ?>
                    <input type="checkbox"
                           class="admin__control-checkbox checkbox<?php if ($_isRequired):?> validate-one-required-by-name<?php endif; ?> product downloadable link"
                           name="links[]" id="links_<?php /* @escapeNotVerified */ echo $_link->getId() ?>"
                           value="<?php /* @escapeNotVerified */ echo $_link->getId(); ?>" <?php /* @escapeNotVerified */ echo $block->getLinkCheckedValue($_link); ?>
                           price="<?php /* @escapeNotVerified */ echo $block->getCurrencyPrice($_link->getPrice()); ?>"/>
                    <?php endif; ?>
                    <label for="links_<?php /* @escapeNotVerified */ echo $_link->getId() ?>" class="label">
                        <?php echo $block->escapeHtml($_link->getTitle()) ?>
                        <?php if ($_link->getSampleFile() || $_link->getSampleUrl()): ?>
                            &nbsp;(<a href="<?php /* @escapeNotVerified */ echo $block->getLinkSampleUrl($_link) ?>" <?php echo $block->getIsOpenInNewWindow()?'onclick="this.target=\'_blank\'"':''; ?>><?php /* @escapeNotVerified */ echo __('sample') ?></a>)
                        <?php endif; ?>
                        <?php if ($_linksPurchasedSeparately): ?>
                        <?php /* @escapeNotVerified */ echo $block->getFormattedLinkPrice($_link); ?>
                            <br />
                            <?php /* @escapeNotVerified */ echo $block->getLinkPrice($_link); ?>
                        <?php endif; ?>
                    </label>
                <?php if ($_isRequired): ?>
                    <script>
require(['prototype'], function(){

    //<![CDATA[
    $('links_<?php /* @escapeNotVerified */ echo $_link->getId() ?>').advaiceContainer = 'links-advice-container';
    $('links_<?php /* @escapeNotVerified */ echo $_link->getId() ?>').callbackFunction = 'validateDownloadableCallback';
    //]]>
                    
});
</script>
                <?php endif; ?>
            </div>
            <?php endforeach; ?>
        <?php if ($_isRequired): ?>
            <span id="links-advice-container"></span>
        <?php endif;?>
        </div>
    </div>
</fieldset>

    <script>
require(['prototype'], function(){

//<![CDATA[
    validateDownloadableCallback = function (elmId, result) {
        var container = $('downloadable-links-list');
        if (result == 'failed') {
            container.removeClassName('validation-passed');
            container.addClassName('validation-failed');
        } else {
            container.removeClassName('validation-failed');
            container.addClassName('validation-passed');
        }
    }
//]]>
    
});
</script>
<?php endif;?>
